//=====================
// SoundManager
//! \file soundmananger.h
//!
//! 
//! 
//=====================


#ifndef _CORE_SOUNDMANAGER__H_
#define _CORE_SOUNDMANAGER__H_

#include <fmod.h> 
#include <fmod.hpp>
#include <string>
#include <vector>
#include "fmod_errors.h"
#include "actor.h"
#include "resourcemanager.h"
#include "vector3.h"


#include "audio.h"

namespace core
{




		//=====================
    // SoundManager
    //! 
    //!
    //! 
    //! 
    //=====================


		struct Boot
		{
				bool stereo;
		};

		typedef boost::shared_ptr<Boot> BootPtr;


		static const int MAX_AUDIO_CHANNELS = 200;
		static const float DEFAULT_SOUNDEFFECT_VOLUME = 0.3F;
		static const float DEFAULT_MUSIC_VOLUME = 0.08F;

		class SoundManager
		{
		
				public:

						//! Get soundmanager instance
						static SoundManager* GetInstance();


						void Init( BootPtr p_Boot );
						

						//!Play an instant soundfx at given position
						void PlaySound( const Vector3& p_Position, AudioPtr p_Sound );

						//! This wil play a global ambient sound, 2D
						//!  Returns an music id/handle for the requested music file
						//!  0 = oneshot.
						//!  1 = loop once then stop.
						//! -1 = loop forever.
						//! -1 is Default
						void PlayMusic( AudioPtr p_Sound, int p_LoopCount );


						//! Stop a playing music file
						void StopMusic( AudioPtr p_Sound );


						//! Pause a playing music file.
						void PauseMusic( AudioPtr p_Sound );


						//! Stop all playing music files.
						void StopAllMusic();


						//! Start a playing music file.
						void UnpauseMusic( AudioPtr p_Sound );


						//! Set volume for a playing music file.
						void SetMuiscVolume( AudioPtr p_Sound, int p_Percent ) ;

						
						//! Set master volume for music files.
						void SetMasterMusicVolume( int p_Percent );


						//! Set master volume for soundeffect files.
						void SetMasterEffectVolume( int p_Percent );


						//! Set up listener with an actor's attributes.
						void SetListener(  Actor&  p_Actor );


						//! Set up listener with position and direction.
						void SetListener( const Vector3& p_Position, const Vector3& p_Direction );
						
					
						//! Update soundManager.\n
						//! Muset be called every frame.
						void update();
								
						
						FMOD::System*		GetFMODSystem() { return( m_System ); }


		protected:

						//singleton
						SoundManager();
						virtual ~SoundManager();
						static SoundManager* m_Single;

						FMOD::System* m_System;
						FMOD_RESULT  m_Result;

						//actor that acts like listener
						Actor*		  m_ActorListener;
						//ActorWPtr				m_ptrActorListener;

						//vecctors for listener
						FMOD_VECTOR	m_ListenerUp;
						FMOD_VECTOR m_ListenerForward;
						FMOD_VECTOR m_ListenerPosition;


						//soundgroup for soundfx
						FMOD::SoundGroup* m_FxSoundGroup;

						//channel group for music 
						FMOD::ChannelGroup* m_MusicChannelGroup;
					
						bool m_actorAsListener;

						//master volumes
						float m_MasterMusicVolume;
						float m_MasterSoundFxVolume;
				
		};

}
#endif

